package com.learning.assignment_1;



import com.learning.database.DatabaseHelper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class RegisterActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register_page);
        
        Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
        btnSubmit.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				DatabaseHelper db = DatabaseHelper.getInstance(getApplicationContext());
				EditText username = (EditText) findViewById(R.id.username);
				EditText password = (EditText) findViewById(R.id.password);
				EditText email = (EditText) findViewById(R.id.email);
				TextView status = (TextView) findViewById(R.id.status);
				
				if (db.checkExistAccount(username.getText().toString())){
					status.setText("This account has already existed");
				}
				else{
					if (db.insertAccount(username.getText().toString(), password.getText().toString(), email.getText().toString())){
						status.setText("Your account has been created successfully");
					}
				}
				
			}
		});
    }

}